const { Sequelize } = require('sequelize');
const sequelize = new Sequelize('ry-vue', 'root', 'root', {
    host: 'localhost',
    port: '3306',
    dialect: 'mysql', /* 选择 'mysql' | 'mariadb' | 'postgres' | 'mssql' 其一 */
});

let dbHelper = {
    sequelize,
    // 校验数据库连接
    CheckConnect: async () => {
        try {
            await sequelize.authenticate();
            console.log('Connection has been established successfully.');
        } catch (error) {
            console.error('Unable to connect to the database:', error);
        }
    },
    // 查询数据
    Query: async (sql, callback) => {
        await sequelize.query(sql, { type: sequelize.QueryTypes.SELECT }).then(function (results) {
            callback(results);
        })
    }
}

module.exports = dbHelper;